package main

import (
	"context"
	"dubbo.apache.org/dubbo-go/v3/config"
	_ "dubbo.apache.org/dubbo-go/v3/imports"
	"dubbo2javaserver/entity"
	"fmt"
	"os"
	"time"
)

var api = new(entity.UserServiceClientImpl)

func main() {
	// 调用服务端
	os.Setenv("DUBBO_GO_CONFIG_PATH", "./conf/dubbogo.yml")
	defer os.Unsetenv("DUBBO_GO_CONFIG_PATH")
	config.SetConsumerService(api)

	if err1 := config.Load(); err1 != nil {
		panic(err1)
	}
	time.Sleep(10 * time.Second)
	userinfo := &entity.Userinfo{
		Username:  "bob-go",
		Age:       18,
		Hobby:     []string{"football", "basketball"},
		Phonetype: entity.PhoneType_MOBILE,
	}

	resp, err := api.SayHello(context.Background(), userinfo)
	if err != nil {
		panic(err)
		return // Now, we explicitly handle the error by logging it and then returning from the function.
	}
	fmt.Println("hello:", resp.GetName())

}
